package com.example.store2.Mapper;

import com.example.store2.pojo.Resources;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface URMapper{
    @Update("update UR set state=#{state},update_time=#{updateTime} where resources_id=#{id} and user_id=#{userId}")
    void update(Resources resources);


    /**
     * 添加资源
     * @param resources
     */
    @Insert("insert into UR(user_id,resources_id,state) values(#{userId},#{id},#{state})")
    void add(Resources resources);
    /**
     * 删除资源
     * @param id
     * @return
     */
    @Delete("delete from UR where UR.resources_id=#{id}")
    void delete(Integer id);


    @Select("select state from UR where resources_id=#{id} and user_id=#{userId}")
    String find(Resources resources);

    @Select("select resources_id from UR where user_id!=#{userId} and resources_id=#{id}")
    List<Integer> list(Resources resources);
    @Delete("delete from UR where UR.resources_id=#{id} and state='他人'")
    void deletebystate(Integer id);

    @Select("select count(*) from UR where UR.user_id=#{userId}")
    Integer count(Resources resources);

    @Select("select count(*) from UR where UR.user_id=#{userId} and UR.resources_id=#{resourcesId}")
    Integer countadd(Integer userId, Integer resourcesId);
}
